package com.zhl.random;

import java.util.Random;

public class RandomDemo1 {
    public static void main(String[] args) {
        //目标：掌握使用Random生成随机数的步骤
        //步骤1：导入java.util.Random类
        //import java.util.Random;
        //步骤2：创建Random类的对象
        //Random random = new Random();
        //步骤3：调用Random类的nextInt()方法，生成一个随机整数
        //int num = random.nextInt(100);
        //步骤4：输出随机整数
        //System.out.println(num);

        Random r = new Random();
        int num = r.nextInt(9);
        System.out.println(num);
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        for (int i = 0; i < 20; i++){
            int num1 = r.nextInt(9);
            System.out.println(num1);
        }

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~");
        // 产生一个1-10之间的随机数
        int num2 = r.nextInt(10) + 1;
        System.out.println(num2);


        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~");
        //产生一个3-17之间的随机数
        int num3 = r.nextInt(14) + 3;
        System.out.println(num3);
    }
}
